﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefQcInspectItem" :model="stateQcInspectItem.vmModel" label-width="100px">
      <el-row>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_TemplateId_FormItem" prop="Entity.TemplateId" :label="$t('message.autotrans._Model_QcInspectItem_Template')">
            <el-select v-model="stateQcInspectItem.vmModel.Entity.TemplateId" clearable>
               <el-option v-for="item in stateQcInspectItem.AllTemplates" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_ProductId_FormItem" prop="Entity.ProductId" :label="$t('message.autotrans._Model_QcInspectItem_ProductId')">
            <el-input v-model="stateQcInspectItem.vmModel.Entity.ProductId" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_ProductName_FormItem" prop="Entity.ProductName" :label="$t('message.autotrans._Model_QcInspectItem_ProductName')">
            <el-input v-model="stateQcInspectItem.vmModel.Entity.ProductName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_QcType_FormItem" prop="Entity.QcType" :label="$t('message.autotrans._Model_QcInspectItem_QcType')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_QcInspectItem_QcType')}), trigger: 'blur' }]" >
            <el-select v-model="stateQcInspectItem.vmModel.Entity.QcType" clearable>
               <el-option key="Equipment" value="Equipment" :label="$t('message.autotrans._Enum_EquipTypeEnum_Equipment')"></el-option>
               <el-option key="Tooling" value="Tooling" :label="$t('message.autotrans._Enum_EquipTypeEnum_Tooling')"></el-option>
               <el-option key="Mould" value="Mould" :label="$t('message.autotrans._Enum_EquipTypeEnum_Mould')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_InspectName_FormItem" prop="Entity.InspectName" :label="$t('message.autotrans._Model_QcInspectItem_InspectName')">
            <el-input v-model="stateQcInspectItem.vmModel.Entity.InspectName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_InspectTool_FormItem" prop="Entity.InspectTool" :label="$t('message.autotrans._Model_QcInspectItem_InspectTool')">
            <el-input v-model="stateQcInspectItem.vmModel.Entity.InspectTool" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Content_FormItem" prop="Entity.Content" :label="$t('message.autotrans._Model_QcInspectItem_Content')">
            <el-input v-model="stateQcInspectItem.vmModel.Entity.Content" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_RefValue_FormItem" prop="Entity.RefValue" :label="$t('message.autotrans._Model_QcInspectItem_RefValue')">
            <el-input v-model="stateQcInspectItem.vmModel.Entity.RefValue" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Remark_FormItem" prop="Entity.Remark" :label="$t('message.autotrans._Model_QcInspectItem_Remark')">
            <el-input v-model="stateQcInspectItem.vmModel.Entity.Remark" clearable></el-input>
        </el-form-item>

        </el-col>
      </el-row>

      <div style="text-align:right;">
        <WtmButton @click="onSubmitQcInspectItem"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

        <WtmButton @click="onCloseQcInspectItem"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageQcManagementQcInspectItemEdit;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { qcinspectitemApi } from '/@/api/qcmanagement/qcinspectitem';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefQcInspectItem = ref();
const stateQcInspectItem = reactive({
    vmModel: {
	  Entity:{
        TemplateId: null,
        ProductId: null,
        ProductName: '',
        QcType: undefined,
        InspectName: '',
        InspectTool: '',
        Content: '',
        RefValue: '',
        Remark: '',
        ID:null,
      },

	},
    
    AllTemplates: [] as any[],
});

// 取消
const onCloseQcInspectItem = () => {
    closeDialog();
};

// 提交
const onSubmitQcInspectItem = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefQcInspectItem.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            qcinspectitemApi().edit(stateQcInspectItem.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};

// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/QcManagement/QcInspectItem/GetQcTemplates',[],false).then(x=>{stateQcInspectItem.AllTemplates = x});
    if (ci.attrs["wtmdata"]) {
		stateQcInspectItem.vmModel.Entity.ID = ci.attrs["wtmdata"].ID;
	}
	else if (useRouter().currentRoute.value.query.id) {
		stateQcInspectItem.vmModel.Entity.ID = useRouter().currentRoute.value.query.id as any;
	}
	qcinspectitemApi().get(stateQcInspectItem.vmModel.Entity.ID ?? "").then((data: any) => other.setValue(stateQcInspectItem.vmModel, data));
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

